﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Software_2Project.DB_Layer;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace Software_2Project.Logic_Layer
{
   public class Logic_Shuffle
    {
        public bool deduct(int acconum, int balance)
        {
            //=================Validating Empty
            if (acconum.ToString() == null || balance < 0 || balance.ToString() == null)
                return false;
            //=================Validating Numbers Only
            string patternWithdraw = @"^\d+$";
            bool matchShuffleWithdraw = Regex.IsMatch(balance.ToString(), patternWithdraw);
            bool matchShuffleWithdraw_1 = Regex.IsMatch(acconum.ToString(), patternWithdraw);

            if (matchShuffleWithdraw==false || matchShuffleWithdraw_1==false)
                return false;

            DB_Shuffle dal = new DB_Shuffle();
            bool found = false;

            

            if (dal.checkShuffleWithdraw( acconum, balance))
            {
                DataTable dt = dal.shuffleWithdraw(acconum,  balance);
                foreach (DataRow dRow in dt.Rows)
                {

                    if ((acconum == int.Parse(dRow["acconum"].ToString())))
                    {


                        //ancedb = Convert.ToInt16(dRow["balance"]);
                        //alancedb = balancedb - newamount ;

                        found = true;

                    }
                    else
                    {
                        found = false;
                    }

                }

            }
            return found;

        }

        public string acconum { get; set; } 
    }
}
